package com.pudu.mydemo.Receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import com.pudu.mydemo.entity.Contant;

/**
 * Created by guiliu on 2016/8/5.
 *
 *  Intent intent = new Intent();
 *  intent.setAction("something_wrong");
 *  intent.putExtra("status",data);
 *  App.context().sendBroadcast(intent);
 */
public class WraningReceiver extends BroadcastReceiver{
    @Override
    public void onReceive(Context context, Intent intent) {
        Log.e("brocast","onReceive"+intent.getAction());
        if("something_wrong".equals(intent.getAction())) {
            int data = intent.getIntExtra("status", Contant.SMAIL_NORMAL);
            String strValue = intent.getStringExtra(Contant.CUSTOM_INFORMATION_STRING);
            Log.e("brocast","data"+data);
            if(strValue == null || strValue.isEmpty() == true) {
                launcherSmailActivity(context, data);
            }else{
                launcherSmailActivity(context, data, strValue);
            }
           /* if(data < 5) {
                //0-4采用代码动画
                launcherSmailActivity(context,data);
            } else if(data >= 5){
                //5以上采用视频动画
                launcherVideoActivity(context,data);
            }*/
        }
    }

    public void launcherSmailActivity(Context context,int data,String strMsg) {
        Intent intent1 = new Intent();
        intent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent1.setAction("smail_action_move_error");
        intent1.putExtra("status",data);
        intent1.putExtra(Contant.CUSTOM_INFORMATION_STRING,strMsg);
        context.startActivity(intent1);
    }

    public void launcherSmailActivity(Context context,int data) {

        Intent intent1 = new Intent();
        intent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent1.setAction("smail_action_move_error");
        intent1.putExtra("status",data);
        context.startActivity(intent1);
    }

    public void launcherVideoActivity(Context context,int data) {
        Intent intent1 = new Intent();
        intent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent1.setAction("video_action_move_error");
        intent1.putExtra("status",data);
        context.startActivity(intent1);
    }
}
